home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 737 / prlabel / prl.c < prev    next >
C/C++ Source or Header  |  1995-03-18  |  33KB  |  1,299 lines

  1. /***************************************************************************
  2.  
  3.    Program:    PrLabel
  4.    File:       PrL.c
  5.    
  6.    Version:    V1.2
  7.    Date:       28.10.91
  8.    Function:   Actual label printing and Interface handling routines
  9.    
  10.    Copyright:  SciTech Software 1991
  11.    Author:     Andrew C. R. Martin
  12.    Address:    SciTech Software
  13.                23, Stag Leys,
  14.                Ashtead,
  15.                Surrey,
  16.                KT21 2TD.
  17.    Phone:      +44 (0372) 275775
  18.    EMail:      UUCP: cbmuk!cbmuka!scitec!amartin
  19.                JANET: andrew@uk.ac.ox.biop
  20.                
  21. ****************************************************************************
  22.  
  23.    This program is Shareware with a suggested donation of £5.00.
  24.    It may be freely copied and distributed for no more than a nominal charge 
  25.    (not more than £4.00 in the U.K.) providing this header is included.
  26.    
  27.    The code may be modified as required, but any modifications must be
  28.    documented so that the person responsible can be identified. If someone
  29.    else breaks this code, I don't want to be blamed for code that does not
  30.    work! The code may not be sold commercially without prior permission from
  31.    the author, although it may be given away free with commercial products,
  32.    providing it is made clear that this program is free and that the source
  33.    code is provided with the program.
  34.  
  35. ****************************************************************************
  36.  
  37.    Description:
  38.    ============
  39.    
  40.    Actual label printing and interface handling routines for PrLabel.
  41.    
  42.    N.B. The values for spacing in SetSheet27() and SetSheet28() have been
  43.         calculated, but never actually tested (I use 3x8 label sheets!).
  44.         Similarly Label27() and Label28().
  45.         
  46.         If you find these values are wrong, please let me know28.10..
  47.  
  48.  
  49. ****************************************************************************
  50.  
  51.    Usage:
  52.    ======
  53.  
  54. ****************************************************************************
  55.  
  56.    Revision History:
  57.    =================
  58.    V1.1     17.01.92
  59.    Changed interface to use STSLib.
  60.    V1.2     14.09.92
  61.    Added code for reading and writing address lists
  62.  
  63. ***************************************************************************/
  64. #include "PrLabel.h"
  65.  
  66. /**************************************************************************/
  67. /* Macros
  68. */
  69. #define NEXT(x)         (x)=(x)->next
  70. #define ALLOCNEXT(x,y)  {  if(((x)->next=(y *)malloc(sizeof(y)))==NULL) \
  71.                               Die("Out of Memory!"); \
  72.                            NEXT(x); \
  73.                            (x)->next=NULL; \
  74.                         }
  75. #define LAST(x)         while((x)->next != NULL) NEXT(x)
  76. #define TOGGLE(x)       (x) = (!(x))
  77. #define TERMINATE(x) {  int j;               \
  78.                         for(j=0; x[j]; j++)  \
  79.                         {  if(x[j] == '\n')  \
  80.                            {  x[j] = '\0';   \
  81.                               break;         \
  82.                      }  }  }
  83.  
  84. /**************************************************************************/
  85. /*>SetSheet38(APTR object)
  86.    -----------------------
  87.    Sets sheet pattern to 3x8
  88.    28.10.91 Original
  89.    14.09.92 Documented
  90. */
  91. SetSheet38(APTR object)
  92. {
  93.    int j;
  94.    
  95.    for(j=0;j<8;j++)
  96.    {
  97.       label[0][j].x =  0;
  98.       label[1][j].x = 28;
  99.       label[2][j].x = 56;
  100.    }
  101.    
  102.    for(j=0;j<3;j++)
  103.    {
  104.       label[j][0].y =  0;
  105.       label[j][1].y =  8;
  106.       label[j][2].y = 16;
  107.       label[j][3].y = 25;
  108.       label[j][4].y = 34;
  109.       label[j][5].y = 43;
  110.       label[j][6].y = 52;
  111.       label[j][7].y = 60;
  112.    }
  113.    
  114.    SheetType = THREE_EIGHT;
  115.    
  116.    return(0);
  117. }
  118.  
  119. /**************************************************************************/
  120. /*>SetSheet28(APTR object)
  121.    -----------------------
  122.    Sets sheet pattern to 2x8
  123.    28.10.91 Original
  124.    14.09.92 Documented
  125. */
  126. SetSheet28(APTR object)
  127. {
  128.    int j;
  129.    
  130.    for(j=0;j<8;j++)
  131.    {
  132.       label[0][j].x =  0;
  133.       label[1][j].x = 43;
  134.       label[2][j].x = LINELENGTH+10; /* Make sure this won't be printed */
  135.    }
  136.  
  137.    for(j=0;j<3;j++)
  138.    {
  139.       label[j][0].y =  0;
  140.       label[j][1].y =  8;
  141.       label[j][2].y = 16;
  142.       label[j][3].y = 25;
  143.       label[j][4].y = 34;
  144.       label[j][5].y = 43;
  145.       label[j][6].y = 52;
  146.       label[j][7].y = 60;
  147.    }
  148.    
  149.    SheetType = TWO_EIGHT;
  150.    
  151.    return(0);
  152. }
  153.  
  154. /**************************************************************************/
  155. /*>SetSheet27(APTR object)
  156.    -----------------------
  157.    Sets sheet pattern to 2x7
  158.    28.10.91 Original
  159.    14.09.92 Documented
  160. */
  161. SetSheet27(APTR object)
  162. {
  163.    int j;
  164.  
  165.    for(j=0;j<8;j++)
  166.    {
  167.       label[0][j].x =  0;
  168.       label[1][j].x = 42;
  169.       label[2][j].x = LINELENGTH+10; /* Make sure this won't be printed */
  170.    }
  171.    
  172.    for(j=0;j<3;j++)
  173.    {
  174.       label[j][0].y =  0;
  175.       label[j][1].y =  9;
  176.       label[j][2].y = 19;
  177.       label[j][3].y = 29;
  178.       label[j][4].y = 39;
  179.       label[j][5].y = 49;
  180.       label[j][6].y = 59;
  181.       label[j][7].y = PAGELENGTH+10; /* Make sure this won't be printed */
  182.    }
  183.  
  184.    SheetType = TWO_SEVEN;
  185.    
  186.    return(0);
  187. }
  188.  
  189. /**************************************************************************/
  190. /*>SetPos11(APTR object)
  191.    ---------------------
  192.    React to click on a label gadget
  193.    28.10.91 Original
  194.    14.09.92 Documented
  195. */
  196. SetPos11(APTR object)
  197. {
  198.    TOGGLE(label[0][0].print);
  199.    return(0);
  200. }
  201.  
  202. /**************************************************************************/
  203. /*>SetPos12(APTR object)
  204.    ---------------------
  205.    React to click on a label gadget
  206.    28.10.91 Original
  207.    14.09.92 Documented
  208. */
  209. SetPos12(APTR object)
  210. {
  211.    TOGGLE(label[0][1].print);
  212.    return(0);
  213. }
  214.  
  215. /**************************************************************************/
  216. /*>SetPos13(APTR object)
  217.    ---------------------
  218.    React to click on a label gadget
  219.    28.10.91 Original
  220.    14.09.92 Documented
  221. */
  222. SetPos13(APTR object)
  223. {
  224.    TOGGLE(label[0][2].print);
  225.    return(0);
  226. }
  227.  
  228. /**************************************************************************/
  229. /*>SetPos14(APTR object)
  230.    ---------------------
  231.    React to click on a label gadget
  232.    28.10.91 Original
  233.    14.09.92 Documented
  234. */
  235. SetPos14(APTR object)
  236. {
  237.    TOGGLE(label[0][3].print);
  238.    return(0);
  239. }
  240.  
  241. /**************************************************************************/
  242. /*>SetPos15(APTR object)
  243.    ---------------------
  244.    React to click on a label gadget
  245.    28.10.91 Original
  246.    14.09.92 Documented
  247. */
  248. SetPos15(APTR object)
  249. {
  250.    TOGGLE(label[0][4].print);
  251.    return(0);
  252. }
  253.  
  254. /**************************************************************************/
  255. /*>SetPos16(APTR object)
  256.    ---------------------
  257.    React to click on a label gadget
  258.    28.10.91 Original
  259.    14.09.92 Documented
  260. */
  261. SetPos16(APTR object)
  262. {
  263.    TOGGLE(label[0][5].print);
  264.    return(0);
  265. }
  266.  
  267. /**************************************************************************/
  268. /*>SetPos17(APTR object)
  269.    ---------------------
  270.    React to click on a label gadget
  271.    28.10.91 Original
  272.    14.09.92 Documented
  273. */
  274. SetPos17(APTR object)
  275. {
  276.    TOGGLE(label[0][6].print);
  277.    return(0);
  278. }
  279.  
  280. /**************************************************************************/
  281. /*>SetPos18(APTR object)
  282.    ---------------------
  283.    React to click on a label gadget
  284.    28.10.91 Original
  285.    14.09.92 Documented
  286. */
  287. SetPos18(APTR object)
  288. {
  289.    TOGGLE(label[0][7].print);
  290.    return(0);
  291. }
  292.  
  293. /**************************************************************************/
  294. /*>SetPos21(APTR object)
  295.    ---------------------
  296.    React to click on a label gadget
  297.    28.10.91 Original
  298.    14.09.92 Documented
  299. */
  300. SetPos21(APTR object)
  301. {
  302.    TOGGLE(label[1][0].print);
  303.    return(0);
  304. }
  305.  
  306. /**************************************************************************/
  307. /*>SetPos22(APTR object)
  308.    ---------------------
  309.    React to click on a label gadget
  310.    28.10.91 Original
  311.    14.09.92 Documented
  312. */
  313. SetPos22(APTR object)
  314. {
  315.    TOGGLE(label[1][1].print);
  316.    return(0);
  317. }
  318.  
  319. /**************************************************************************/
  320. /*>SetPos23(APTR object)
  321.    ---------------------
  322.    React to click on a label gadget
  323.    28.10.91 Original
  324.    14.09.92 Documented
  325. */
  326. SetPos23(APTR object)
  327. {
  328.    TOGGLE(label[1][2].print);
  329.    return(0);
  330. }
  331.  
  332. /**************************************************************************/
  333. /*>SetPos24(APTR object)
  334.    ---------------------
  335.    React to click on a label gadget
  336.    28.10.91 Original
  337.    14.09.92 Documented
  338. */
  339. SetPos24(APTR object)
  340. {
  341.    TOGGLE(label[1][3].print);
  342.    return(0);
  343. }
  344.  
  345. /**************************************************************************/
  346. /*>SetPos25(APTR object)
  347.    ---------------------
  348.    React to click on a label gadget
  349.    28.10.91 Original
  350.    14.09.92 Documented
  351. */
  352. SetPos25(APTR object)
  353. {
  354.    TOGGLE(label[1][4].print);
  355.    return(0);
  356. }
  357.  
  358. /**************************************************************************/
  359. /*>SetPos26(APTR object)
  360.    ---------------------
  361.    React to click on a label gadget
  362.    28.10.91 Original
  363.    14.09.92 Documented
  364. */
  365. SetPos26(APTR object)
  366. {
  367.    TOGGLE(label[1][5].print);
  368.    return(0);
  369. }
  370.  
  371. /**************************************************************************/
  372. /*>SetPos27(APTR object)
  373.    ---------------------
  374.    React to click on a label gadget
  375.    28.10.91 Original
  376.    14.09.92 Documented
  377. */
  378. SetPos27(APTR object)
  379. {
  380.    TOGGLE(label[1][6].print);
  381.    return(0);
  382. }
  383.  
  384. /**************************************************************************/
  385. /*>SetPos28(APTR object)
  386.    ---------------------
  387.    React to click on a label gadget
  388.    28.10.91 Original
  389.    14.09.92 Documented
  390. */
  391. SetPos28(APTR object)
  392. {
  393.    TOGGLE(label[1][7].print);
  394.    return(0);
  395. }
  396.  
  397. /**************************************************************************/
  398. /*>SetPos31(APTR object)
  399.    ---------------------
  400.    React to click on a label gadget
  401.    28.10.91 Original
  402.    14.09.92 Documented
  403. */
  404. SetPos31(APTR object)
  405. {
  406.    TOGGLE(label[2][0].print);
  407.    return(0);
  408. }
  409.  
  410. /**************************************************************************/
  411. /*>SetPos32(APTR object)
  412.    ---------------------
  413.    React to click on a label gadget
  414.    28.10.91 Original
  415.    14.09.92 Documented
  416. */
  417. SetPos32(APTR object)
  418. {
  419.    TOGGLE(label[2][1].print);
  420.    return(0);
  421. }
  422.  
  423. /**************************************************************************/
  424. /*>SetPos33(APTR object)
  425.    ---------------------
  426.    React to click on a label gadget
  427.    28.10.91 Original
  428.    14.09.92 Documented
  429. */
  430. SetPos33(APTR object)
  431. {
  432.    TOGGLE(label[2][2].print);
  433.    return(0);
  434. }
  435.  
  436. /**************************************************************************/
  437. /*>SetPos34(APTR object)
  438.    ---------------------
  439.    React to click on a label gadget
  440.    28.10.91 Original
  441.    14.09.92 Documented
  442. */
  443. SetPos34(APTR object)
  444. {
  445.    TOGGLE(label[2][3].print);
  446.    return(0);
  447. }
  448.  
  449. /**************************************************************************/
  450. /*>SetPos35(APTR object)
  451.    ---------------------
  452.    React to click on a label gadget
  453.    28.10.91 Original
  454.    14.09.92 Documented
  455. */
  456. SetPos35(APTR object)
  457. {
  458.    TOGGLE(label[2][4].print);
  459.    return(0);
  460. }
  461.  
  462. /**************************************************************************/
  463. /*>SetPos36(APTR object)
  464.    ---------------------
  465.    React to click on a label gadget
  466.    28.10.91 Original
  467.    14.09.92 Documented
  468. */
  469. SetPos36(APTR object)
  470. {
  471.    TOGGLE(label[2][5].print);
  472.    return(0);
  473. }
  474.  
  475. /**************************************************************************/
  476. /*>SetPos37(APTR object)
  477.    ---------------------
  478.    React to click on a label gadget
  479.    28.10.91 Original
  480.    14.09.92 Documented
  481. */
  482. SetPos37(APTR object)
  483. {
  484.    TOGGLE(label[2][6].print);
  485.    return(0);
  486. }
  487.  
  488. /**************************************************************************/
  489. /*>SetPos38(APTR object)
  490.    ---------------------
  491.    React to click on a label gadget
  492.    28.10.91 Original
  493.    14.09.92 Documented
  494. */
  495. SetPos38(APTR object)
  496. {
  497.    TOGGLE(label[2][7].print);
  498.    return(0);
  499. }
  500.  
  501. /**************************************************************************/
  502. /*>PrintLabels(APTR object)
  503.    ------------------------
  504.    Actually prints the labels.
  505.    28.10.91 Original
  506.    14.09.92 Documented
  507. */
  508. PrintLabels(APTR object)
  509. {
  510.    int  labelcount,
  511.         j,
  512.         k;
  513.    /* This is only declared as static, to get it off the stack. Once the
  514.       stack resizing option is documented for Lattice C, this can be used
  515.       instead.
  516.    */
  517.    static char PageBuffer[PAGELENGTH][LINELENGTH];
  518.    ADDR *p;
  519.    
  520.    /* Move to current address label and copy buffers into linked list */
  521.    for(p=address,j=0; p!=NULL && j<CurLabel; NEXT(p), j++);
  522.    strcpy(p->line[0], Line1SIBuff);
  523.    strcpy(p->line[1], Line2SIBuff);
  524.    strcpy(p->line[2], Line3SIBuff);
  525.    strcpy(p->line[3], Line4SIBuff);
  526.    strcpy(p->line[4], Line5SIBuff);
  527.    strcpy(p->line[5], Line6SIBuff);
  528.    strcpy(p->line[6], Line7SIBuff);
  529.  
  530.    /* Blank the buffer */
  531.    BlankBuffer(PageBuffer);
  532.    
  533.    /* If there's only one label defined, we'll print it at each active
  534.       label position
  535.    */
  536.    if(NLabel == 1)
  537.    {
  538.       for(j=0;j<3;j++)
  539.          for(k=0;k<8;k++)
  540.             if(label[j][k].print) PrintAt(PageBuffer,label[j][k].x,label[j][k].y,0);
  541.    }
  542.    else
  543.    {
  544.       labelcount = 0;
  545.       for(j=0;j<3;j++)
  546.          for(k=0;k<8;k++)
  547.             if(label[j][k].print) 
  548.             {
  549.                if(labelcount < NLabel)
  550.                   PrintAt(PageBuffer, label[j][k].x, label[j][k].y, labelcount++);
  551.             }
  552.    }
  553.    
  554.    DumpBuffer(PageBuffer);
  555.  
  556.    /* Reactivate line1 gadget */
  557.    GoLine1((APTR)1);
  558.    
  559.    return(0);
  560. }
  561.  
  562. /**************************************************************************/
  563. /*>PrevLabel(APTR object)
  564.    ----------------------
  565.    Step to the previous label.
  566.    28.10.92 Original
  567.    14.09.92 Documented
  568. */
  569. PrevLabel(APTR object)
  570. {
  571.    ADDR *p;
  572.    int  j;
  573.    
  574.    /* Move to current address label and copy buffers into linked list */
  575.    for(p=address,j=0; p!=NULL && j<CurLabel; NEXT(p), j++);
  576.    strcpy(p->line[0], Line1SIBuff);
  577.    strcpy(p->line[1], Line2SIBuff);
  578.    strcpy(p->line[2], Line3SIBuff);
  579.    strcpy(p->line[3], Line4SIBuff);
  580.    strcpy(p->line[4], Line5SIBuff);
  581.    strcpy(p->line[5], Line6SIBuff);
  582.    strcpy(p->line[6], Line7SIBuff);
  583.  
  584.    CurLabel--;
  585.    
  586.    if(CurLabel < 0) CurLabel = 0;
  587.    
  588.    /* Put vales for this label in buffers */
  589.    for(p=address,j=0; p!=NULL && j<CurLabel; NEXT(p), j++);
  590.    strcpy(Line1SIBuff, p->line[0]);
  591.    strcpy(Line2SIBuff, p->line[1]);
  592.    strcpy(Line3SIBuff, p->line[2]);
  593.    strcpy(Line4SIBuff, p->line[3]);
  594.    strcpy(Line5SIBuff, p->line[4]);
  595.    strcpy(Line6SIBuff, p->line[5]);
  596.    strcpy(Line7SIBuff, p->line[6]);
  597.    
  598.    RefreshGList(Line1,Window,NULL,7);
  599.    
  600.    /* Reactivate line1 gadget */
  601.    GoLine1((APTR)1);
  602.    
  603.    return(0);
  604. }
  605.  
  606. /**************************************************************************/
  607. /*>NextLabel(APTR object)
  608.    ----------------------
  609.    Step to the next label.
  610.    28.10.92 Original
  611.    14.09.92 Documented
  612. */
  613. NextLabel(APTR object)
  614. {
  615.    ADDR *p;
  616.    int  j;
  617.  
  618.    /* Move to current address label and copy buffers into linked list */
  619.    for(p=address,j=0; p!=NULL && j<CurLabel; NEXT(p), j++);
  620.    strcpy(p->line[0], Line1SIBuff);
  621.    strcpy(p->line[1], Line2SIBuff);
  622.    strcpy(p->line[2], Line3SIBuff);
  623.    strcpy(p->line[3], Line4SIBuff);
  624.    strcpy(p->line[4], Line5SIBuff);
  625.    strcpy(p->line[5], Line6SIBuff);
  626.    strcpy(p->line[6], Line7SIBuff);
  627.    
  628.    CurLabel++;
  629.    p = address;
  630.    
  631.    /* Allocate space for next address if necessary */
  632.    while(NLabel <= CurLabel)
  633.    {
  634.       LAST(p);
  635.       ALLOCNEXT(p,ADDR);
  636.       if(!p)
  637.       {
  638.          ReqMessage(Window,"No memory for next label!",0);
  639.       }
  640.       else
  641.       {
  642.          NLabel++;
  643.          p->line[0][0] = '\0';
  644.          p->line[1][0] = '\0';
  645.          p->line[2][0] = '\0';
  646.          p->line[3][0] = '\0';
  647.          p->line[4][0] = '\0';
  648.          p->line[5][0] = '\0';
  649.          p->line[6][0] = '\0';
  650.          p->next = NULL;
  651.       }
  652.    }
  653.    
  654.    /* Move to current address label and put values in buffers */
  655.    for(p=address,j=0; p!=NULL && j<CurLabel; NEXT(p), j++);
  656.    strcpy(Line1SIBuff,p->line[0]);
  657.    strcpy(Line2SIBuff,p->line[1]);
  658.    strcpy(Line3SIBuff,p->line[2]);
  659.    strcpy(Line4SIBuff,p->line[3]);
  660.    strcpy(Line5SIBuff,p->line[4]);
  661.    strcpy(Line6SIBuff,p->line[5]);
  662.    strcpy(Line7SIBuff,p->line[6]);
  663.  
  664.    RefreshGList(Line1,Window,NULL,7);
  665.  
  666.    /* Reactivate line1 gadget */
  667.    GoLine1((APTR)1);
  668.    
  669.    return(0);
  670. }
  671.  
  672. /**************************************************************************/
  673. /*>KillLabel(APTR object)
  674.    ----------------------
  675.    Kill the current label unless only 1 left
  676.    28.10.92 Original
  677.    14.09.92 Documented
  678. */
  679. KillLabel(APTR object)
  680. {
  681.    ADDR *p;
  682.    int  j;
  683.    
  684.    if(NLabel > 1)
  685.    {
  686.       /* Deal with special case */
  687.       if(CurLabel == 0)
  688.       {
  689.          p = address->next;
  690.          free(address);
  691.          address = p;
  692.       }
  693.       else
  694.       {
  695.          ADDR *q;
  696.          /* Move to previous address label in list */
  697.          for(p=address,j=0; p!=NULL && j<CurLabel-1; NEXT(p), j++);
  698.          /* Save the next pointer from the address label we're going to kill */
  699.          q = p->next->next;
  700.          /* Kill the address label */
  701.          free(p->next);
  702.          /* Update the pointer */
  703.          p->next = q;
  704.          /* Move on if there's another address label */
  705.          if(q)
  706.             p = q;
  707.          else
  708.             CurLabel--;
  709.       }
  710.       
  711.       /* Decrement number of address labels */
  712.       NLabel--;
  713.       
  714.       /* Refresh buffers */
  715.       for(p=address,j=0; p!=NULL && j<CurLabel; NEXT(p), j++);
  716.       strcpy(Line1SIBuff, p->line[0]);
  717.       strcpy(Line2SIBuff, p->line[1]);
  718.       strcpy(Line3SIBuff, p->line[2]);
  719.       strcpy(Line4SIBuff, p->line[3]);
  720.       strcpy(Line5SIBuff, p->line[4]);
  721.       strcpy(Line6SIBuff, p->line[5]);
  722.       strcpy(Line7SIBuff, p->line[6]);
  723.    
  724.       RefreshGList(Line1,Window,NULL,7);
  725.    }
  726.    
  727.    /* Reactivate line1 gadget */
  728.    GoLine1((APTR)1);
  729.    
  730.    return(0);
  731. }
  732.  
  733. /**************************************************************************/
  734. /*>PrintAt(char PageBuffer[PAGELENGTH][LINELENGTH], int xpos, int ypos,
  735.            int labelnum)
  736.    --------------------------------------------------------------------
  737.    Fill in the buffer for a label at a particular position
  738.    28.10.92 Original
  739.    14.09.92 Documented
  740. */
  741. PrintAt(char PageBuffer[PAGELENGTH][LINELENGTH],
  742.         int xpos,
  743.         int ypos,
  744.         int labelnum)
  745. {
  746.    int j,
  747.        k;
  748.    ADDR *p;
  749.  
  750.    /* Set p to point to the address item in which we're interested */
  751.    for(p=address,j=0; p!=NULL && j<labelnum; NEXT(p), j++);
  752.    
  753.    /* For each line of an address */
  754.    for(j=0;j<NLABLIN; j++)
  755.    {
  756.       /* Break out if we're off the page */
  757.       if(ypos+j >= PAGELENGTH) continue;
  758.       
  759.       /* For each character in the line */
  760.       for(k=0;k<strlen(p->line[j]);k++)
  761.       {
  762.          /* Break out if we're off the page */
  763.          if(xpos+k >= LINELENGTH) break;
  764.          
  765.          /* Copy the characters into the page buffer */
  766.          PageBuffer[ypos+j][xpos+k] = p->line[j][k];
  767.       }
  768.    }
  769.    return(0);
  770. }
  771.  
  772. /**************************************************************************/
  773. /*>DumpBuffer(char PageBuffer[PAGELENGTH][LINELENGTH])
  774.    ---------------------------------------------------
  775.    Dump the buffer to the printer
  776.    28.10.92 Original
  777.    14.09.92 Documented
  778. */
  779. DumpBuffer(char PageBuffer[PAGELENGTH][LINELENGTH])
  780. {
  781.    int j;
  782.    struct FileHandle *fh;
  783.    
  784.    if(fh=(struct FileHandle *)Open("PRT:",MODE_OLDFILE))
  785.    {
  786.       /* For each line */
  787.       for(j=0; j<PAGELENGTH; j++)
  788.       {
  789.          /* Ensure line is correctly terminated */
  790.          PageBuffer[j][LINELENGTH-1] = '\0';
  791.          /* Dump to the printer */
  792.          Write(fh,PageBuffer[j],strlen(PageBuffer[j]));
  793.          Write(fh,"\n",1);
  794.       }
  795.       Close(fh);
  796.    }
  797.    
  798.    return(0);
  799. }
  800.  
  801. /**************************************************************************/
  802. /*>BlankBuffer(char PageBuffer[PAGELENGTH][LINELENGTH])
  803.    ----------------------------------------------------
  804.    Clear the print buffer
  805.    28.10.92 Original
  806.    14.09.92 Documented
  807. */
  808. BlankBuffer(char PageBuffer[PAGELENGTH][LINELENGTH])
  809. {
  810.    int j,
  811.        k;
  812.  
  813.    for(j=0;j<PAGELENGTH;j++)
  814.    {
  815.       for(k=0;k<LINELENGTH;k++)
  816.          PageBuffer[j][k] = ' ';
  817.       PageBuffer[j][LINELENGTH-1] = '\0';
  818.    }
  819.       
  820.    return(0);
  821. }
  822.  
  823. /**************************************************************************/
  824. /*>GoLine1(APTR object)
  825.    --------------------
  826.    Move to label line 1 by activating the gadget
  827.    28.10.91 Original
  828.    14.09.92 Documented
  829. */
  830. GoLine1(APTR object)
  831. {
  832.    ActivateGadget(Line1,Window,NULL);
  833.    return(0);
  834. }
  835.  
  836. /**************************************************************************/
  837. /*>GoLine2(APTR object)
  838.    --------------------
  839.    Move to label line 2 by activating the gadget
  840.    28.10.91 Original
  841.    14.09.92 Documented
  842. */
  843. GoLine2(APTR object)
  844. {
  845.    ActivateGadget(Line2,Window,NULL);
  846.    return(0);
  847. }
  848.  
  849. /**************************************************************************/
  850. /*>GoLine3(APTR object)
  851.    --------------------
  852.    Move to label line 3 by activating the gadget
  853.    28.10.91 Original
  854.    14.09.92 Documented
  855. */
  856. GoLine3(APTR object)
  857. {
  858.    ActivateGadget(Line3,Window,NULL);
  859.    return(0);
  860. }
  861.  
  862. /**************************************************************************/
  863. /*>GoLine4(APTR object)
  864.    --------------------
  865.    Move to label line 4 by activating the gadget
  866.    28.10.91 Original
  867.    14.09.92 Documented
  868. */
  869. GoLine4(APTR object)
  870. {
  871.    ActivateGadget(Line4,Window,NULL);
  872.    return(0);
  873. }
  874.  
  875. /**************************************************************************/
  876. /*>GoLine5(APTR object)
  877.    --------------------
  878.    Move to label line 5 by activating the gadget
  879.    28.10.91 Original
  880.    14.09.92 Documented
  881. */
  882. GoLine5(APTR object)
  883. {
  884.    ActivateGadget(Line5,Window,NULL);
  885.    return(0);
  886. }
  887.  
  888. /**************************************************************************/
  889. /*>GoLine6(APTR object)
  890.    --------------------
  891.    Move to label line 6 by activating the gadget
  892.    28.10.91 Original
  893.    14.09.92 Documented
  894. */
  895. GoLine6(APTR object)
  896. {
  897.    ActivateGadget(Line6,Window,NULL);
  898.    return(0);
  899. }
  900.  
  901. /**************************************************************************/
  902. /*>GoLine7(APTR object)
  903.    --------------------
  904.    Move to label line 7 by activating the gadget
  905.    28.10.91 Original
  906.    14.09.92 Documented
  907. */
  908. GoLine7(APTR object)
  909. {
  910.    ActivateGadget(Line7,Window,NULL);
  911.    return(0);
  912. }
  913.  
  914. /**************************************************************************/
  915. /*>Label38(void)
  916.    -------------
  917.    Set the gadget labelling for labels 3x8
  918.    28.10.91 Original
  919.    14.09.92 Documented
  920. */
  921. Label38(void)
  922. {
  923.    struct IntuiText *itext;
  924.    
  925.    /* Label the Y-axis */
  926.    itext = MakeText(NULL,"6",1,97,mb+14,0);
  927.    MakeText(itext,"7",1,97,mb+28,0);
  928.    MakeText(itext,"7",1,97,mb+42,0);
  929.    MakeText(itext,"7",1,97,mb+56,0);
  930.    MakeText(itext,"7",1,97,mb+70,0);
  931.    MakeText(itext,"7",1,97,mb+84,0);
  932.    MakeText(itext,"7",1,97,mb+98,0);
  933.    MakeText(itext,"3",1,97,mb+112,0);
  934.  
  935.    /* Label the X-axis */
  936.    MakeText(itext,"26",1,15,mb+125,0);
  937.    MakeText(itext,"26",1,43,mb+125,0);
  938.    MakeText(itext,"20",1,71,mb+125,0);
  939.  
  940.    PrintIText(Window->RPort,itext,0,-8);
  941.  
  942.    FreeIText(itext);
  943.  
  944.    return(0);
  945. }
  946.  
  947. /**************************************************************************/
  948. /*>Label28(void)
  949.    -------------
  950.    Set the gadget labelling for labels 2x8
  951.    28.10.91 Original
  952.    14.09.92 Documented
  953. */
  954. Label28(void)
  955. {
  956.    struct IntuiText *itext;
  957.    
  958.    /* Label the Y-axis */
  959.    itext = MakeText(NULL,"6",1,72,mb+14,0);
  960.    MakeText(itext,"7",1,72,mb+28,0);
  961.    MakeText(itext,"7",1,72,mb+42,0);
  962.    MakeText(itext,"7",1,72,mb+56,0);
  963.    MakeText(itext,"7",1,72,mb+70,0);
  964.    MakeText(itext,"7",1,72,mb+84,0);
  965.    MakeText(itext,"7",1,72,mb+98,0);
  966.    MakeText(itext,"3",1,72,mb+112,0);
  967.  
  968.    /* Label the X-axis */
  969.    MakeText(itext,"39",1,15,mb+125,0);
  970.    MakeText(itext,"34",1,43,mb+125,0);
  971.  
  972.    PrintIText(Window->RPort,itext,0,-8);
  973.  
  974.    FreeIText(itext);
  975.  
  976.    return(0);
  977. }
  978.  
  979. /**************************************************************************/
  980. /*>Label27(void)
  981.    -------------
  982.    Set the gadget labelling for labels 2x7
  983.    28.10.91 Original
  984.    14.09.92 Documented
  985. */
  986. Label27(void)
  987. {
  988.    struct IntuiText *itext;
  989.    
  990.    /* Label the Y-axis */
  991.    itext = MakeText(NULL,"7",1,72,mb+14,0);
  992.    MakeText(itext,"7",1,72,mb+28,0);
  993.    MakeText(itext,"7",1,72,mb+42,0);
  994.    MakeText(itext,"7",1,72,mb+56,0);
  995.    MakeText(itext,"7",1,72,mb+70,0);
  996.    MakeText(itext,"7",1,72,mb+84,0);
  997.    MakeText(itext,"4",1,72,mb+98,0);
  998.  
  999.    /* Label the X-axis */
  1000.    MakeText(itext,"39",1,15,mb+111,0);
  1001.    MakeText(itext,"34",1,43,mb+111,0);
  1002.  
  1003.    PrintIText(Window->RPort,itext,0,-8);
  1004.  
  1005.    FreeIText(itext);
  1006.  
  1007.    return(0);
  1008. }
  1009.  
  1010. /**************************************************************************/
  1011. /* Displays an About message
  1012.    28.10.91 Original
  1013.    17.01.92 Updated for distribution
  1014.    14.09.92 Documented
  1015. */
  1016. About(APTR object)
  1017. {
  1018.    struct IntuiText *itext1,
  1019.                     *itext2,
  1020.                     *itext3,
  1021.                     *oktext;
  1022.    
  1023.    oktext  = MakeText(NULL,"OK",1,0,0,0);
  1024.  
  1025.    itext1 = MakeText(NULL,"PrLabel V1.2",      1,52, 0,0);
  1026.    MakeText(itext1,"Label Printing Utility",   1,12,10,0);
  1027.    MakeText(itext1,"SciTech Software ©1992",   1,12,20,0);
  1028.    MakeText(itext1," ",                        1, 0,30,0);
  1029.    MakeText(itext1,"This program is shareware",1, 0,40,0);
  1030.    MakeText(itext1,"and uses the STSLib",      1, 0,50,0);
  1031.    MakeText(itext1,"gadget and menu library",  1, 0,60,0);
  1032.    
  1033.    itext2 = MakeText(NULL,"PrLabel V1.2",      1,52, 0,0);
  1034.    MakeText(itext2,"Suggested fee £5.00",      1,24,10,0);
  1035.    MakeText(itext2," ",                        1, 0,20,0);
  1036.    MakeText(itext2,"STSLib provides 3D-look",  1, 0,30,0);
  1037.    MakeText(itext2,"gadgets and menu support", 1, 0,40,0);
  1038.    MakeText(itext2,"under V1.3 and V2.0",      1, 0,50,0);
  1039.    MakeText(itext2," ",                        1, 0,60,0);
  1040.    MakeText(itext2,"STSLib is £20.00 from:",   1, 0,70,0);
  1041.    
  1042.    itext3 = MakeText(NULL,"SciTech Software",  1, 0, 0,0);
  1043.    MakeText(itext3,"23, Stag Leys,",           1, 0,10,0);
  1044.    MakeText(itext3,"Ashtead,",                 1, 0,20,0);
  1045.    MakeText(itext3,"Surrey",                   1, 0,30,0);
  1046.    MakeText(itext3,"KT21 2TD.",                1, 0,40,0);
  1047.    MakeText(itext3," ",                        1, 0,50,0);
  1048.    MakeText(itext3,"Tel.: +44(0372)275775",    1, 0,60,0);
  1049.  
  1050.    STSAutoRequest(NULL,itext1,oktext,oktext,NULL,NULL,0,0);
  1051.    STSAutoRequest(NULL,itext2,oktext,oktext,NULL,NULL,0,0);
  1052.    STSAutoRequest(NULL,itext3,oktext,oktext,NULL,NULL,0,0);
  1053.    
  1054.    FreeIText(itext1);
  1055.    FreeIText(itext2);
  1056.    FreeIText(itext3);
  1057.    
  1058.    return(0);
  1059. }
  1060. /**************************************************************************/
  1061. /*>ReadList(APTR object)
  1062.    ---------------------
  1063.    Reads in an address list
  1064.    31.05.92 Original
  1065.    14.09.92 Tidied for release
  1066. */
  1067. #include "myio.h"
  1068. #define  MAXBUFF 400
  1069.  
  1070. ReadList(APTR object)
  1071. {
  1072.    ADDR     *p;
  1073.    int      j,
  1074.             first;
  1075.    IOBUFF   iobuff;
  1076.    char     buffer[MAXBUFF],
  1077.             fbuff[320],
  1078.             buff2[80],
  1079.             *ptr;
  1080.    struct   FileHandle  *fh;
  1081.    static   char  fname[160],
  1082.                   fdir[160];
  1083.  
  1084.    if(GetAFile(AslBase,Window,NULL,"Read address list",fname,fdir,fbuff))
  1085.    {
  1086.       if((fh = (struct FileHandle *)Open(fbuff,MODE_OLDFILE)) == NULL)
  1087.       {
  1088.          ReqMessage2(Window,"Unable to open file",fbuff,0);
  1089.       }
  1090.       else
  1091.       {
  1092.          /* Move to end of current address label list */
  1093.          p = address;
  1094.          LAST(p);
  1095.          first = TRUE;
  1096.    
  1097.          /* Read in a record at a time from the file */
  1098.          iobuff.firstcall = TRUE;
  1099.          while(mygetsbuff(fh,buffer,MAXBUFF,&iobuff))
  1100.          {
  1101.             TERMINATE(buffer);
  1102.             
  1103.             for(j=0, ptr=buffer; j<7 && *ptr; j++)
  1104.             {
  1105.                /* Blank the line buffer */
  1106.                p->line[j][0] = '\0';
  1107.                
  1108.                /* Extract a line from the buffer, using the global
  1109.                   separator character as a record delimiter
  1110.                */
  1111.                ptr = GetLine(ptr,buff2,GlobSepChar);
  1112.                strcpy(p->line[j],buff2);
  1113.             }
  1114.  
  1115.             if(first)
  1116.             {
  1117.                strcpy(Line1SIBuff,p->line[0]);
  1118.                strcpy(Line2SIBuff,p->line[1]);
  1119.                strcpy(Line3SIBuff,p->line[2]);
  1120.                strcpy(Line4SIBuff,p->line[3]);
  1121.                strcpy(Line5SIBuff,p->line[4]);
  1122.                strcpy(Line6SIBuff,p->line[5]);
  1123.                strcpy(Line7SIBuff,p->line[6]);
  1124.                
  1125.                first = FALSE;
  1126.             }
  1127.  
  1128.             /* Allocate space for the next one */
  1129.             ALLOCNEXT(p,ADDR);
  1130.             if(!p)
  1131.             {
  1132.                ReqMessage(Window,"No memory for next label!",0);
  1133.             }
  1134.             else
  1135.             {
  1136.                NLabel++;
  1137.                p->line[0][0] = '\0';
  1138.                p->line[1][0] = '\0';
  1139.                p->line[2][0] = '\0';
  1140.                p->line[3][0] = '\0';
  1141.                p->line[4][0] = '\0';
  1142.                p->line[5][0] = '\0';
  1143.                p->line[6][0] = '\0';
  1144.                p->next = NULL;
  1145.             }
  1146.                
  1147.          }
  1148.          Close(fh);
  1149.       }
  1150.    }
  1151.  
  1152.    RefreshGList(Line1,Window,NULL,7);
  1153.  
  1154.    /* Reactivate line1 gadget */
  1155.    GoLine1((APTR)1);
  1156.    
  1157.    return(0);
  1158. }
  1159. /**************************************************************************/
  1160. /*>char *GetLine(char *inbuff, char *outbuff, char delim)
  1161.    ------------------------------------------------------
  1162.    Gets a string out of inbuff into outbuff delimited by delim. Returns
  1163.    pointer within inbuff, after outbuff extracted.
  1164.    31.05.92 Original
  1165.    14.09.92 Documented
  1166. */
  1167.  
  1168. char *GetLine(char *inbuff, char *outbuff, char delim)
  1169. {
  1170.    int i;
  1171.    
  1172.    for(i=0; inbuff[i]!='\0' && inbuff[i] != delim; i++) outbuff[i] = inbuff[i];
  1173.    outbuff[i] = '\0';
  1174.    return(inbuff+i+1);
  1175. }
  1176.  
  1177. /**************************************************************************/
  1178. /* SaveList(APTR object)
  1179.    ---------------------
  1180.    Writes out an address list to a file
  1181.    14.09.92 Original
  1182. */
  1183. SaveList(APTR object)
  1184. {
  1185.    ADDR                 *p;
  1186.    int                  j;
  1187.    char                 buffer[568],
  1188.                         fbuff[256];
  1189.    struct   FileHandle  *fh;
  1190.    static   char        fname[160],
  1191.                         fdir[160];
  1192.  
  1193.    if(GetAFile(AslBase,Window,NULL,"Write address list",fname,fdir,fbuff))
  1194.    {
  1195.       if((fh = (struct FileHandle *)Open(fbuff,MODE_NEWFILE)) == NULL)
  1196.       {
  1197.          ReqMessage2(Window,"Unable to open file",fbuff,0);
  1198.       }
  1199.       else
  1200.       {
  1201.          /* Move to start of address label list */
  1202.          for(p = address; p!=NULL; NEXT(p))
  1203.          {
  1204.             /* Build the lines into the buffer */
  1205.             buffer[0] = '\0';
  1206.  
  1207.             for(j=0;j<7;j++)
  1208.             {
  1209.                int len;
  1210.                len           = strlen(buffer);
  1211.                if(len)
  1212.                {
  1213.                   buffer[len]   = GlobSepChar;
  1214.                   buffer[len+1] = '\0';
  1215.                }
  1216.                strcat(buffer,p->line[j]);
  1217.             }
  1218.  
  1219.             /* Write buffer to the file */
  1220.             myputs(fh,buffer);
  1221.             myputs(fh,"\n");
  1222.          }
  1223.          Close(fh);
  1224.       }
  1225.    }
  1226.  
  1227.    /* Reactivate line1 gadget */
  1228.    GoLine1((APTR)1);
  1229.    
  1230.    return(0);
  1231. }
  1232.  
  1233. /**************************************************************************/
  1234. /*>CreateIText(struct IntuiText  *str, SHORT left, SHORT top, UBYTE *mesg)
  1235.    -----------------------------------------------------------------------
  1236.    Build a string into an IntuiText structure. Used for ReqMessage2()
  1237.    14.09.92 Extracted from my general support library
  1238. */
  1239. static struct TextAttr CIT_TOPAZ80 = {
  1240.    (STRPTR)"topaz.font",
  1241.    TOPAZ_EIGHTY,0,0
  1242. };
  1243.  
  1244. CreateIText(struct IntuiText  *str,
  1245.             SHORT             left,
  1246.             SHORT             top,
  1247.             UBYTE             *mesg)
  1248. {
  1249.    str->FrontPen  = 0;
  1250.    str->BackPen   = 1;
  1251.    str->DrawMode  = JAM1;
  1252.    str->LeftEdge  = left;
  1253.    str->TopEdge   = top;
  1254.    str->ITextFont = &CIT_TOPAZ80;
  1255.    str->IText     = mesg;
  1256.    str->NextText  = NULL;
  1257.    return(0);
  1258. }
  1259. /**************************************************************************/
  1260. /*>ReqMessage2(struct Window *wind, char *string1, char *string2, int flag)
  1261.    ------------------------------------------------------------------------
  1262.    Display a 2 line requester message. If flag is TRUE, provide both OK
  1263.    and CANCEL; else just OK.
  1264.    14.09.92 Extracted from my general support library. OK it should use
  1265.             STSLib, but I was in a hurry!
  1266. */
  1267. #define MAX(a,b) (((a)>(b)) ? (a) : (b))
  1268.  
  1269. ReqMessage2(struct Window *wind,
  1270.             char          *string1,
  1271.             char          *string2,
  1272.             int           flag)
  1273. {
  1274.    struct IntuiText  IText1,
  1275.                      IText2,
  1276.                      OK,
  1277.                      CANCEL;
  1278.    int               clen,
  1279.                      plen,
  1280.                      offset = 32;
  1281.    
  1282.    clen = MAX(strlen(string1),strlen(string2));
  1283.    plen = clen * 8;
  1284.  
  1285.    CreateIText(&IText1,offset+4*(clen-strlen(string1)),25,string1);
  1286.    CreateIText(&IText2,offset+4*(clen-strlen(string2)),35,string2);
  1287.    IText1.NextText = &IText2;
  1288.  
  1289.    CreateIText(&OK,AUTOLEFTEDGE,AUTOTOPEDGE,"OK");
  1290.    CreateIText(&CANCEL,AUTOLEFTEDGE,AUTOTOPEDGE,"CANCEL");
  1291.    
  1292.    if(flag)
  1293.       return(STSAutoRequest(wind,&IText1,&OK,&CANCEL,NULL,NULL,plen+64,110));
  1294.    else
  1295.       return(STSAutoRequest(wind,&IText1,&OK,&OK,NULL,NULL,plen+64,110));
  1296.    
  1297.    return(0);
  1298. }
  1299.